package com.cn.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cn.pojo.Collect;
import com.cn.pojo.Dish;
import com.cn.response.Result;
import com.cn.service.CollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@Slf4j
@Api(tags = "收藏管理")
@RequestMapping("/collect")
public class CollectController {
    @Autowired
    CollectService collectService;

    @ApiModelProperty(value = "通过用户id查询收藏列表",notes = "通过用户id查询收藏列表")
    @PostMapping("/getCollectList")
    public Result getCollectList(@RequestParam(value = "current", required = true, defaultValue = "1") Integer current,
                                 @RequestParam(value = "size", required = true, defaultValue = "5") Integer size,
                                 @RequestParam(value = "nickName" ,required = false) String nickName
                                 )
    {
        Page<Dish> page = new Page<>(current, size);
        Page<Collect> collects = collectService.collectList(page,nickName);
        return Result.ok().data("collectlist", collects);
    }

    @ApiModelProperty(value = "通过id删除指定收藏列表",notes = "通过id删除指定收藏列表")
    @GetMapping("/deleteCollectList")
    public Result deleteCollectList(@RequestParam("id") Long id)
    {
        Integer num = collectService.deleteCollect(id);
        if (num > 0) {
            return Result.ok().data("code", 200);
        } else {
            return Result.ok().data("code", 0);
        }
    }

}
